package com.library.controller;/*
 *@author lzg
 *@data 2020/11/30
 */

import com.library.entity.Admin;
import com.library.entity.Reader;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/logout")
public class LogoutServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        Admin admin = (Admin) session.getAttribute("admin");
        Reader reader = (Reader) session.getAttribute("reader");
        if (admin != null){
            session.removeAttribute("admin");
        }
        if (reader != null){
            session.removeAttribute("reader");
        }
        session.invalidate();
        req.getRequestDispatcher("login.jsp").forward(req,resp);
    }
}
